<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
	<head>
		<title>用户管理</title>
<script type="text/javascript">
		var datatable_content ;
	  	$(function(){
			initTable();
		});
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			  "bServerSide":true,
	           "sAjaxSource":'${ctx}/v2/admin/user/page',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true, 
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": "realname"},
	             	 {"mData": null},
	             	 {"mData": "jobuuid"},
	             	 {"mData": null},
	             ],
	             
	             "aoColumnDefs":[
	             	 {"aTargets": [1],
		              "mRender": function (data, display, row) {
						    return "<a href=\"${ctx}/v2/admin/user/update/"+row.id+"\">"+row.username+"</a>";
			           }
		            },	
		            {"aTargets": [3],
		              "mRender": function (data, display, row) {
		              		var rs = "";
							for (var i=0;i<row.roleList.length;i++){
								rs+=row.roleList[i].roleintro+";  ";
							}
							return rs;
						}
		            },
	             	 {"aTargets": [5],
		              "mRender": function (data, display, row) {
		                    var rs = "";
		                    if(row.status == '1'){
		                    	rs = "<a href=\"${ctx}/v2/admin/user/delete/"+row.id+"\">删除</a>";
		                    }
							if(row.status == '0'){
				                 rs = "已经删除";
				            }
				            if(row.status == '2'){
				                rs = "<a href=\"javascript:ajaxUpdateUser('"+row.jobuuid+"')\" class=\"btn btn-primary\">审核</a>";  
				            }
						    return rs;
			           }
		            },
	             ]
			});
		}
		var filterParam = {};
		function callback( sSource, aoData, fnCallback ) {
		 var formParam = $("#queryForm").serializeArray();
			for(var n in filterParam){
				formParam.push(filterParam[n]);
			}
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });   
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
		
		function ajaxUpdateUser(item) {
			$.ajax({
						type : 'post',
						url : '${ctx}/yhdLead/ajaxUpdateUser',
						data : 'jobuuid=' + item,
						dataType : 'json',
						success : function(data) {
							
								alert(data.content);
							
						},
						error : function() {
							alert("获取信息错误！");
						}
					});
		}
</script>
	</head>

	<body>
	<section class="content">
	<!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				<div class="box-body">
    <form class="form-search" id="queryForm" method="post" style="margin-top: 10px;">
    <div class="form-group row">
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">登陆名:</span>
						<input class="form-control"  type="text" id="_username" name="_EQ_username" value="${param._EQ_username}" />
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">真实姓名:</span>
						<input class="form-control" type="text" id="_realname" name="_EQ_realname" value="${param._EQ_realname}" />
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<button class="btn btn-primary" type="button" style="margin-left: 10px;" onclick="query()">搜索</button>
						<a class="btn btn-primary" href="${ctx}/v2/admin/user/create">创建用户</a>
					</div>
				</div>
		</div>
    </form>
    </div>
    </div>
    </div>
    </div>
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success">
				<button data-dismiss="alert" class="close">
					×
				</button>
				${message}
			</div>
		</c:if>
<div class="form-group row"  style="margin-top: 5px;">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed"  style="margin-top: 0px;">
			<thead>
				<tr>
					<th style="width: 20px;">
						序号
					</th>
					<th style="width: 70px;">
						登录名
					</th>
					<th style="width: 70px;">
						真实姓名
					</th>
					<th style="width: 190px;">
						角色
					</th>
					<th style="width: 190px;">
						工号
					</th>
					<th style="width: 50px;">
						管理
					</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
		</table>
		</div>
		</div>
		</div>
		</div>
		</section>
	</body>
</html>
